home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / Ph 1.1.1 / PhClient / pswd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-08  |  4.0 KB  |  146 lines  |  [TEXT/MPS ]

  1. /*_____________________________________________________________________
  2.  
  3.       pswd.c - Server Transaction Movable Modal Dialog.
  4. _____________________________________________________________________*/
  5.  
  6. #pragma load "precompile"
  7. #include "rez.h"
  8. #include "pswd.h"
  9. #include "utl.h"
  10. #include "glob.h"
  11. #include "oop.h"
  12. #include "wstm.h"
  13.  
  14. /*_____________________________________________________________________
  15.  
  16.     Global Variables.
  17. _____________________________________________________________________*/
  18.  
  19. static DialogPtr        Window;            /* ptr to dialog window */
  20. static Str255            Pswd1;            /* first password */
  21. static Str255            Pswd2;            /* second password */
  22.  
  23. static oop_Dispatch    dispatch = {
  24.                                 pswd_DoPeriodic,
  25.                                 oop_DoClick,
  26.                                 pswd_DoKey,
  27.                                 oop_DoUpdate,
  28.                                 oop_DoActivate,
  29.                                 oop_DoDeactivate,
  30.                                 oop_DoGrow,
  31.                                 oop_DoZoom,
  32.                                 oop_DoClose,
  33.                                 pswd_DoCommand
  34.                             };
  35.  
  36. /*_____________________________________________________________________
  37.  
  38.     pswd_DoPeriodic - Do Periodic Tasks.
  39.     
  40.     Entry:    w = pointer to window record.
  41. _____________________________________________________________________*/
  42.  
  43. void pswd_DoPeriodic (WindowPtr w)
  44.  
  45. {
  46.     oop_DoPeriodic(w);
  47.     glob_CheckPswdSel(w);
  48. }
  49.  
  50. /*_____________________________________________________________________
  51.  
  52.     pswd_DoKey - Process a Key Down Event.
  53.     
  54.     Entry:    w = pointer to window record.
  55.                 key = ascii code of key.
  56.                 modifiers = modifiers from event record.
  57. _____________________________________________________________________*/
  58.  
  59. void pswd_DoKey (WindowPtr w, char key, short modifiers)
  60.  
  61. {
  62.     char                    *pswd;        /* pointer to Pswd1 or Pswd2 */
  63.  
  64.     pswd = utl_GetDialogEditFieldNum(w) == pswdField1 ? Pswd1 : Pswd2;
  65.     if (!glob_FilterPswdChar(w, key, modifiers, pswd)) return;
  66.     oop_DoKey(w, key, modifiers);
  67. }
  68.  
  69. /*_____________________________________________________________________
  70.  
  71.     pswd_DoCommand - Process a Command.
  72.     
  73.     Entry:    w = pointer to window record.
  74.                 theMenu = menu index.
  75.                 theItem = item index.
  76.                 
  77.     Exit:        function result = true if command handled.
  78. _____________________________________________________________________*/
  79.  
  80. Boolean pswd_DoCommand (WindowPtr w, short theMenu, short theItem)
  81.  
  82. {
  83.     char                    *pswd;        /* pointer to Pswd1 or Pswd2 */
  84.  
  85.     pswd = utl_GetDialogEditFieldNum(w) == pswdField1 ? Pswd1 : Pswd2;
  86.     if (theMenu == editID && theItem != selectAllCmd) {
  87.         glob_FilterPswdEditCmd(w, theItem, pswd);
  88.         return true;
  89.     }
  90.     return oop_DoCommand(w, theMenu, theItem);
  91. }
  92.  
  93. /*_____________________________________________________________________
  94.  
  95.     pswd_DoDialog - Do Change Password Dialog.
  96.     
  97.     Entry:    pswd1 = inital value for first password field.
  98.                 pswd2 = initial value for second password field.
  99.     
  100.     Exit:        function result = true if canceled by user.
  101.                 pswd1 = first password.
  102.                 pswd2 = second password.
  103. _____________________________________________________________________*/
  104.  
  105. Boolean pswd_DoDialog (Str255 pswd1, Str255 pswd2)
  106.  
  107. {
  108.     short            itemHit;        /* item hit */
  109.     Str255        bullets;        /* string of bullets for initial password field */
  110.  
  111.     ShowCursor();
  112.     Window = wstm_Restore(true, pswdDlogID, nil, &PswdState);
  113.     utl_CopyPString(Pswd1, pswd1);
  114.     utl_CopyPString(Pswd2, pswd2);
  115.     *bullets = *pswd1;
  116.     memset(bullets+1, '•', *pswd1);
  117.     utl_SetDialogText(Window, pswdField1, bullets);
  118.     SelIText(Window, pswdField1, 0, 0x7fff);
  119.     *bullets = *pswd2;
  120.     memset(bullets+1, '•', *pswd2);
  121.     utl_SetDialogText(Window, pswdField2, bullets);
  122.     SetPort(Window);
  123.     TextFont(0);
  124.     TextSize(12);
  125.     oop_NewDialog(Window, pswdModal, nil, &dispatch, true,
  126.         pswdOK, pswdCancel);
  127.     ShowWindow(Window);
  128.     while (true) {
  129.         oop_ClearWindItemHit(Window);
  130.         while (!(itemHit = oop_GetWindItemHit(Window)) && !Done) 
  131.             oop_DoEvent(nil, everyEvent, 
  132.                 oop_InForeground() ? shortSleep : longSleep, nil);
  133.         if (Done) itemHit = pswdCancel;
  134.         if (itemHit == pswdCancel) break;
  135.         break;
  136.     }
  137.     if (itemHit == pswdOK) {
  138.         utl_CopyPString(pswd1, Pswd1);
  139.         utl_CopyPString(pswd2, Pswd2);
  140.     }
  141.     wstm_Save(Window, &PswdState);
  142.     oop_DoClose(Window);
  143.     InitCursor();
  144.     return itemHit == pswdCancel;
  145. }
  146.